<%@ page contentType="text/html;charset=UTF-8"%>
<%
// 进行乱码处理
request.setCharacterEncoding("UTF-8") ;
%>
<%
	//使用脚本而不是表达式，因为表单控件用表达式很繁琐
	//String requestpath = null;
	int pagesize =5;
	int currentpage = 1;
	int pagecount = 0;
	int rowcount = 0;
%>


<%
	// 需要从外面接收以下参数--------------------------------------------
	//requestpath = request.getParameter("requestpath");
	try {
		pagesize = Integer.parseInt(request.getParameter("pagesize"));
		currentpage = Integer.parseInt(request
				.getParameter("currentpage"));
		rowcount = Integer.parseInt(request.getParameter("rowcount"));
		pagecount = Integer.parseInt(request.getParameter("pagecount"));
	} catch (Exception e) {
	}
	// 计算总页数
	//pagecount = (rowcount + pagesize - 1) / pagesize;//this.pagesize is wrong
%>

<script language="javaScript">
var currentPage=<%=currentpage%>;
var pageSize=<%=pagesize%>;
function openPage(curpage){
   	currentPage=curpage;
	setAction();
   	document.spage.submit() ;
}

function setAction(){
	var url=location.pathname;
	var search=location.search;
	//url =url+"?"+"page.currentPage="+document.spage['page.currentPage'].value
	//+"&page.pageSize="+document.spage['page.pageSize'].value;
	url =url+"?"+"page.currentPage="+currentPage
	+"&page.pageSize="+pageSize;
	//alert(url);
	if(search!=null){
		var newSearch="";
		search=search.substring(1);
		var vars=search.split("&");
		for(var i=0;i<vars.length;i++){
			if(vars[i].indexOf("page.")==-1){
				newSearch+=("&"+vars[i]);
			}
		}
		url=url+newSearch;
		//alert(newSearch);
	}
	document.spage.action=url;
}
</script>
<form name="spage" action="" method="post">
	
	<%
		if (rowcount > 0) {
	%>
	<button  type="submit" onClick="openPage(1)"
		<%=currentpage == 1 ? "disabled" : ""%> >首页</button>
	<button  type="submit" onClick="openPage(<%=currentpage - 1%>)"
		<%=currentpage == 1 ? "disabled" : ""%> >上一页</button>
	<button  type="submit" onClick="openPage(<%=currentpage + 1%>)"
		<%=currentpage == pagecount ? "disabled" : ""%> >下一页</button>
	<button  type="submit" onClick="openPage(<%=pagecount%>)"
		<%=currentpage == pagecount ? "disabled" : ""%> >尾页</button>
	<font color="red" size="5"><%=currentpage %></font> /
	<font color="red" size="5"><%=pagecount %></font> 跳转到
	
	<select name="selpage" onChange="openPage(this.value)">
		<%
			for (int x = 1; x <= pagecount; x++) {
		%>
		<option value="<%=x%>" <%=currentpage == x ? "selected" : ""%> >
		<%=x%></option>
		<%
			}
		%>
	</select>
	页
	<%
		}
	%>
</form>
